﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GenericLibrariesToolKit;
using Model;
using BLL.Users;
using BLL.Users.Impl;
using BLL.Privilege;
using BLL.Privilege.Impl;
using Utils;
using Utils.Cache;
using BLL.Info;
using BLL.Info.Impl;
namespace DaoSupportDemo
{
    /// <summary>
    /// 调用DaoSupport的一个Demowewew
    /// </summary>
    class Program
    {
        private static UserBO userBO = new UserBOImpl();

        static void Main(string[] args)
        {
            //应用程序初始化
            string datatSource = @"Data Source = 172.22.119.178; Initial Catalog = QuickKnowledge; User Id = QuickKnowledge_24; Password = 000000";
            InitialConfiguration.ScanPath = "Model";
            InitialConfiguration.DataSource = datatSource;
            InitialConfiguration.Initialization();


            ////初始化缓存
            //CacheUtil.InitializationCacheUtil();

            //UserBO userBO = new UserBOImpl();
            //List<User> userList = userBO.GetScrollData().ResultList;

            //foreach (User user in userList)
            //{
            //    CacheUtil.AddEntity(user.UserId, user);
            //    Console.WriteLine(user.UserId);
            //}
            
            //Program.Add();
            //Program.Delete()
            //Program.Update();
            //Program.Find();
            //RoleModelRight roleModelRight = new RoleModelRightImpl();
            //roleModelRight.GetRoleRight();
            //showRoleRight();
            //
           // ShowNewsTop10();
            ExpertBO expertBO = new ExpertBOImpl();
            expertBO.GetExpertByName("www");
            Console.Read();
        }

        //显示事件信息Top10列表
        private static  void ShowNewsTop10()
        {
            EventBO eventBO = new EventBOImpl();
            List<Event> events= eventBO.ShowTopEvent(10);
            Console.WriteLine(events[0].EventClickAmount.ToString());
        }

        private static void showRoleRight()
        {
            Console.WriteLine("12");
            foreach (KeyValuePair<string, Dictionary<string, int>> pair in RoleModelRightImpl.roleModelRight)
            {
                Console.WriteLine(pair.Key.ToString());
                foreach (KeyValuePair<string, int> pair1 in pair.Value)
                {
                    Console.WriteLine(pair1.Key.ToString() + "  " + pair1.Value.ToString());
                }
            }
        }
        /// <summary>
        /// 添加新用户
        /// </summary>
        private static void Add()
        {
            User user = new User
            {
                UserId = "Admin",
                UserType = "Expert",
                UserPassword = EncryptUtil.Encode("000000"),
                SecurityQuestion="123",
                SecurityAnswer="123",
            };
            bool reuslt = userBO.Add(user);
            Console.WriteLine("新增实体操作：" + reuslt);
        }

        private static void Find()
        {
            User user = userBO.Find("ljl");
            Console.WriteLine(user.UserId+" , " +user.UserPassword);
        }

        private static void Delete()
        {
            bool result = userBO.Delete("ljl");
            Console.WriteLine(result);
        }

        private static void Update()
        {
            User user = userBO.Find("ljl");
            user.UserType="WebMaster";
            userBO.Update(user);
        }

    }
}
